# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=evince
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.34.1
pkgrel=1
arch=('any')
pkgdesc="Document (PostScript, PDF) viewer (mingw-w64)"
license=("GPL 2")
url="https://www.gnome.org"
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-djvulibre"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-gspell"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-hicolor-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-libarchive"
         "${MINGW_PACKAGE_PREFIX}-libgxps"
         "${MINGW_PACKAGE_PREFIX}-libspectre"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-nss"
         "${MINGW_PACKAGE_PREFIX}-poppler"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gettext"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-itstool"
             #"${MINGW_PACKAGE_PREFIX}-meson"
             #"${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-yelp-tools"
             "automake-wrapper"
             "autoconf"
             "intltool"
             "libtool"
             "make")
install=evince-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        0001-build-for-win7-and-more.patch
        0002-missing-include.patch
        0003-mingw-dont-have-fcntl.patch
        0004-fix-linking-syntex.patch
        0005-previewer-unix-prin-only.patch
        0006-yelp-no-symlinks.patch)
sha256sums=('85e407cde396147b249120d816c7715fb6df191ca561cf65ff3554a5d67626df'
            'a331f7da10a17585ec079c2ed9025cf1f2c5964f4058969a369786309cbfe29a'
            'd2850c4bdfa87fa56bae2674d2c798f9181bfb3f19319fbc9966672caae48237'
            '035f9cd952daa040d32309398b73022d199e27fed756126eb15663fb6a435c45'
            '885a9c3483b444a46545e5854dfd71e2f681895373fb53888de733f01a9adc0c'
            '4e6a1ae77d36f0b36ea68ec2cc3abe4a706355ba02e4066d1b9add138052ba1b'
            '9e197aeecc000c8763b1856f56278d3c9ca0eb00f1e3d6cb8d0f1ad80663485b')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-build-for-win7-and-more.patch
  patch -p1 -i ${srcdir}/0002-missing-include.patch
  patch -p1 -i ${srcdir}/0003-mingw-dont-have-fcntl.patch
  patch -p1 -i ${srcdir}/0004-fix-linking-syntex.patch
  patch -p1 -i ${srcdir}/0005-previewer-unix-prin-only.patch
  patch -p1 -i ${srcdir}/0006-yelp-no-symlinks.patch

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib \
    --enable-introspection \
    --disable-gtk-doc \
    --disable-dbus \
    --disable-browser-plugin \
    --disable-nautilus

  make
  
  # ${MINGW_PREFIX}/bin/meson \
    # --buildtype=plain \
    # -Dplatform=win32 \
    # -Dbrowser_plugin=false \
    # -Ddbus=false \
    # -Dnautilus=false \
    # -Dgtk_unix_print=disabled \
    # "../${_realname}-${pkgver}"

  # ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
